package uni.j2ee.forum.request;

import uni.j2ee.forum.helper.CommonHelper;
import uni.j2ee.forum.model.ForumData;
import uni.j2ee.forum.model.ForumUser;
import uni.j2ee.forum.navigation.Navigation;

public class LoginRequest {
	/**
	 * user name of the user 
	 */
	private String username;
	/**
	 * password of the user
	 */
	private String password;
	
	public String login() {
		for(ForumUser user: ForumData.getInstance().getUsers()) {
			if(user.getUsername().equalsIgnoreCase(username) && user.getPassword().equals(password)) {
				CommonHelper.putSessionMap("user", user);
				CommonHelper.addMessage("login_ok", false);
				return Navigation.POSTS;
			}
		}
		
		CommonHelper.addMessage("login_incorrect", true);
		return null;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
}
